package com.itheima.leyou.controller;

import com.itheima.leyou.service.StockService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class StockController {
    @Resource
    private StockService stockService;

    /**
     * 查询商品列表
     */
    @RequestMapping(value = "/getStockList")
    public Map<String, Object> getStockList(HttpServletRequest request){
        return stockService.getStockList();
    }

    /**
     * 根据spu_id查询商品
     * @param sku_id
     * @return
     */
    @RequestMapping(value = "/getStockBySKU/{sku_id}")
    public Map<String, Object> getStockBySPU(@PathVariable("sku_id") String sku_id){
        return stockService.getStock(sku_id);
    }

    /**
     * 新增秒杀政策
     */
    @RequestMapping(value = "/insertLimitPolicy/{jsonObj}")
    public Map<String, Object> insertLimitPolicy(@PathVariable("jsonObj") String jsonObj){
        return stockService.insertLimitPolicy(jsonObj);
    }

}
